package com.hdjk.view.activity.personalcenter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.hdjk.view.R;
import com.hdjk.view.fragment.history.FundHistoricalTransactionFragment;
import com.hdjk.view.fragment.history.GroupHistoricalTransactionFragment;
import com.lst.projectlib.base.BaseActivity;
import com.lst.projectlib.component.CustomView.PagerSlidingTabStrip;

import java.util.ArrayList;
import java.util.List;

/**
 * 历史交易页
 * Created by sxy on 2017/11/3.
 */

public class HistoricalTransactionActivity extends BaseActivity implements View.OnClickListener {
    private PagerSlidingTabStrip mTabs =null;
    private com.lst.projectlib.component.CustomView.TopTitleBar ttb_title_bar;
    private List<Fragment> mFramentList = null;
    private ViewPager mViewPager = null;

    private void bindViews() {
        ttb_title_bar = (com.lst.projectlib.component.CustomView.TopTitleBar) findViewById(R.id.ttb_title_bar);
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    }
    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_historical_transaction);
        bindViews();
        ttb_title_bar.findViewById(R.id.tvNavBack).setOnClickListener(this);
    }

    @Override
    protected void initData() {
        mFramentList = new ArrayList<>();
        mFramentList.add(new FundHistoricalTransactionFragment());
        mFramentList.add(new GroupHistoricalTransactionFragment());
        mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        mTabs.setViewPager(mViewPager);

        mViewPager.setOffscreenPageLimit(0);// 预加载页面的数量
        mViewPager.setCurrentItem(0);
    }

    public class MyPagerAdapter extends FragmentPagerAdapter  {

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        private final String[] titles = { "基金和理财","组合"};

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Fragment getItem(int position) {
            return mFramentList.get(position);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tvNavBack:
                back();
                break;
        }
    }
}
